<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\Db;
/**
* 职位管理
*/
class Jianlis extends AdminBase
{
	
	protected function _initialize()
	{
		parent::_initialize();
	}
    public function tj()
    {
        $list = db('jianlis')->select();
        foreach ($list as $key => $value) {
            if (!$value['tuijian']) {
                $id = $value['id'];
                $str_tuijian = createNonceStr(2).$id.createNonceStr(1);
                db('jianlis')->where(['id'=>$id])->update(['tuijian'=>$str_tuijian]);
            }
        }
    }
	public function index(){
        $where = [];
        $title = input('title');
        $title && $where['name'] = ['like',"%$title%"];
		$list = db('jianlis')->where($where)->order('update_time desc')->paginate(15);
		return $this->fetch('index',['list'=>$list]);
	}
	public function edit($id){
		$res = db('jianlis')
           ->where('id',$id)
           ->find();
        $res['shixi_start'] = json_decode($res['shixi_start'],true);
        $res['shixi_end'] = json_decode($res['shixi_end'],true);
        $res['shixi_company'] = json_decode($res['shixi_company'],true);
        $res['shixi_zw'] = json_decode($res['shixi_zw'],true);
        $res['shixi_daiyu'] = json_decode($res['shixi_daiyu'],true);
		return $this->fetch('edit',['rows'=>$res]);
	}
	/*
	 * 更新'0'或'1'
	 */
	public function flag($id){
        if (request()->isPost()) {
            $data = input('post.');
            if (db('jianlis')->where(['id' => $id])->update($data) !== false) {
                $this->success('更新成功');
            } else {
                $this->error('更新失败');
            }
        }
    }
    /*
     * 更新'0','1','2'
     */
    public function status($id){
        if (request()->isPost()) {
            $data = input('post.');
            if (db('jianlis')->where(['id' => $id])->update($data) !== false) {
                $this->success('更新成功');
            } else {
                $this->error('更新失败');
            }
        }
    }
    public function status1($id){
        if (request()->isPost()) {
            $data = input('post.');
            if (db('jianlis')->where(['id' => $id])->update($data) !== false) {
                $this->success('更新成功');
            } else {
                $this->error('更新失败');
            }
        }
    }
    public function status2($id){
        if (request()->isPost()) {
            $data = input('post.');
            if (db('jianlis')->where(['id' => $id])->update($data) !== false) {
                $this->success('更新成功');
            } else {
                $this->error('更新失败');
            }
        }
    }
    public function delete($id = 0, $ids = [])
    {
        $id = $ids ? $ids : $id;
        if ($id) {
            if (db('jianlis')->delete($id)) {
                $this->success('删除成功');
            } else {
                $this->error('删除失败');
            }
        } else {
            $this->error('请选择需要删除的项目');
        }
    }
    public function downloads(){
        $header[]=array("ID","姓名","英文名","生日(年)","生日(月)","生日(日)","性别","身高","体重","家庭地址","现居地","邮箱","手机","学校","专业","入学时间(年)","入学时间(月)","毕业时间(年)","毕业时间(月)","工作时长","语言能力","求职意向","自我介绍","推荐码","创建简历时间","最后更新简历时间");
        $list= db("jianlis")
            ->field('id,name,en_name,birthday1,birthday2,birthday3,sex,height,weight,address,newaddress,email,tel,school,specialty,school_start1,school_start2,school_end1,school_end2,working_hours,languages,intention,introduce,tuijian,add_time,update_time')
//            ->where('id','<','5000')
//            ->where('id','between','5000,10000')
            ->where('id','>','10000')
            ->order('id')
            ->select();
//        halt($list);
        $data = array_merge_recursive($header,$list);

        // array_unshift($header,$list);
        //      $data = array(
        //  array(NULL, 2010, 2011, 2012),
        //  array('Q1',   12,   15,   21),
        //  array('Q2',   56,   73,   86),
        //  array('Q3',   52,   61,   69),
        //  array('Q4',   30,   32,    0),
        // );
        create_xls($data,'users.xls');
    }

}